package ase.eleitweg.server.db;

import java.util.List;

import ase.eleitweg.common.Document;
import ase.eleitweg.common.Edge;
import ase.eleitweg.common.Group;
import ase.eleitweg.common.Node;
import ase.eleitweg.common.Run;
import ase.eleitweg.common.User;
import ase.eleitweg.common.Workflow;

public interface ELeitwegDAO {
	/**
	 * @return All users stored in the DB
	 */
	public List<User> getUsers();

	/**
	 * Returns user with given id (if exists), otherwise null
	 * 
	 * @param id
	 * @return
	 */
	public User getUserById(int id);

	/**
	 * @return The list of all groups - also containing their users.
	 */
	public List<Group> getGroups();

	/**
	 * @return Retunrs group with given id (if exists), otherwise null
	 */
	public Group getGroupById(int id);

	/**
	 * Returns all groups of which user u is a member
	 * 
	 * @param u
	 * @return
	 */
	public List<Group> getUsersGroups(User u);

	/**
	 * Returns all users of a given group (if exists), otherwise null
	 * 
	 * @param g
	 * @return
	 */
	public List<User> getUsersOfGroup(Group g);

	/**
	 * Add a new user to the database
	 * 
	 * @param u
	 */
	public int createUser(User u);

	/**
	 * Add a new group to the database. If the Group already has any assigned
	 * users, make sure these users are already in the db before calling this
	 * function!
	 * 
	 * @param g
	 */
	public int createGroup(Group g);

	/**
	 * Adds user u to group g and stores this information in the database. Make
	 * sure that u is already in the db before calling this function.
	 * 
	 * @param g
	 * @param u
	 */
	public void addUserToGroup(Group g, User u);
	
	
	/**
	 * Deletes association from group g to user u
	 * @param g
	 * @param u
	 */
	public void deleteUserGroup(Group g, User u);

	/**
	 * Updates the information of user u. You cannot update a user that is not
	 * in the database so make sure that the user with the given id exists.
	 * 
	 * @param u
	 */
	public void updateUser(User u);

	/**
	 * Update the information of group g. You cannot update a group that is not
	 * in the database so make sure that the group with the given id exists.
	 * Also make sure that the users of g are already in the database.
	 * @param g
	 */
	public void updateGroup(Group g);

	/**
	 * Delete group g from database
	 * @param g
	 */
	public void deleteGroup(Group g);

	/**
	 * Delete user u from database 
	 * @param u
	 */
	public void deleteUser(User u);
	
	/**
	 * Creates a Workflow
	 * @param w
	 */
	public int createWorkflow(Workflow w);
	
	/**
	 * Creates an Instance
	 * @param i
	 */
	public int createInstance(Run i);
	
	/**
	 * Creates a Document
	 * @param d
	 */
	public int createDocument(Document d);
	
	/**
	 * Deletes a Document
	 * @param d
	 */
	public void deleteDocument(Document d);
	
	/**
	 * Deletes all Documents associated with the instance, given by the instance id
	 * @param inr
	 */
	public void deleteDocumentsfromInstance(int inr);
	
	/**
	 * Deletes a Workflow
	 * @param w
	 */
	public void deleteWorkflow(Workflow w);
	
	/**
	 * Deletes an Instance
	 * @param i
	 */
	public void deleteInstance(Run i);
	
	/**
	 * Updates a Workflow
	 * @param w
	 */
	public void updateWorkflow(Workflow w);
	
	/**
	 * Updates an Instance
	 * @param i
	 */
	public void updateInstance(Run i);
	
	/**
	 * Retrieves a Workflow
	 * @param wnr
	 * @return Workflow
	 */
	public Workflow getWorkflow(int wnr);
	
	/**
	 * Retrieves all Workflows
	 * @return List<Workflow>
	 */
	public List<Workflow> getAllWorkflows();
	
	/**
	 * Gets Instances
	 * @param wnr
	 * @return List<Run>
	 */
	public List<Run> getInstances(int wnr);
	
	/**
	 * Gets Instances
	 * @param wnr
	 * @param anr
	 * @return List<Run>
	 */
	public List<Run> getInstances(int wnr, int anr);
	
	/**
	 * Retrieves an instance by the given id
	 * @param inr
	 * @return
	 */
	public Run getInstanceById(int inr);
	
	/**
	 * Gets Instances
	 * @return List<Run>
	 */
	public List<Run> getInstances();
	
	/**
	 * Retrieves Documents
	 * @param runId
	 * @return List<Document>
	 */
	public List<Document> getDocuments(int runId);
	
	/**
	 * Retrieves Documents without there binaries
	 * @param runId
	 * @return
	 */
	public List<Document> getDocumentWithoutData(int runId);
	
	public void destroy();
}
